package com.media.system.controller;

import com.media.system.common.core.domain.AjaxResult;
import com.media.system.service.LoginService;
import com.media.system.service.dto.LoginRequest;
import com.media.system.service.dto.RegisterRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 认证控制器（简化版）
 * 
 * @author Claude
 * @since 2024-01-20
 */
@Slf4j
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@Tag(name = "认证管理", description = "登录注册相关接口")
public class AuthControllerSimple {

    private final LoginService loginService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public AjaxResult login(@RequestBody LoginRequest request) {
        return loginService.login(request);
    }

    /**
     * 用户注册
     */
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public AjaxResult register(@RequestBody RegisterRequest request) {
        return loginService.register(request);
    }

    /**
     * 用户注销
     */
    @PostMapping("/logout")
    @Operation(summary = "用户注销")
    public AjaxResult logout() {
        return loginService.logout();
    }

    /**
     * 刷新令牌
     */
    @PostMapping("/refresh")
    @Operation(summary = "刷新令牌")
    public AjaxResult refresh(@RequestParam String refreshToken) {
        return loginService.refreshToken(refreshToken);
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/info")
    @Operation(summary = "获取用户信息")
    public AjaxResult getInfo() {
        return loginService.getCurrentUserInfo();
    }

}